﻿using System;
using System.Linq;
using System.Data.Linq;
using UniMana.Data;
using UniMana.Utils.Configs;

namespace UniMana.Data
{
    public static class Log_RemoveProfileData
    {
        public static bool m_bFlag = false;

        /// <summary>
        /// Lấy tất cả dữ liệu
        /// </summary>
        /// <param name="nLog_ForceCanceled"></param>
        /// <returns></returns>

        public static IQueryable GetAllData(this Table<Log_RemoveProfile> nLog_RemoveProfile)
        {
            var values = from t in nLog_RemoveProfile
                         orderby t.Log_RemoveProfileKey descending
                         select t;
            return values;
        }

        /// <summary>
        /// Lấy dữ liệu user đã yêu cầu
        /// </summary>
        /// <param name="nLog_Tranfer"></param>
        /// <param name="m_strUserKey"></param>
        /// <returns></returns>

        public static IQueryable GetDataWithUserKey(this Table<Log_RemoveProfile> nLog_RemoveProfile,
            string m_strUserKey)
        {
            var values = from t in nLog_RemoveProfile
                         orderby t.Log_RemoveProfileKey descending
                         select new
                         {
                             t.Log_RemoveProfileKey,
                             t.Training_StudentKey,
                             t.ID,
                             t.Training_TrainingProgramKey,
                             t.Catalogue_LevelKey,
                             t.Catalogue_TrainingTypeKey,
                             t.Catalogue_CourseKey,
                             t.Catalogue_MajorKey,
                             t.RequireUser,
                             t.RequireTime,
                             t.CensorshipUser,
                             t.CensorshipTime,
                             t.Reasons,
                             t.Feedback,
                             t.Permit,
                             t.Refuse,
                             Status = t.Status == false ? "Chờ duyệt" : t.Permit == true ? "Đã duyệt" : "Không duyệt"
                         };
            if ((m_strUserKey != "") || (m_strUserKey != DefaultConfig.EMPTY_GUID))
                values = values.Where(tb => tb.RequireUser.ToString() == m_strUserKey);
            return values;
        }

        /// <summary>
        /// Kiểm tra sinh viên có đang chờ duyệt buộc thôi học
        /// </summary>
        /// <param name="nLog_ForceCanceled"></param>
        /// <param name="m_strStudentKey"></param>
        /// <param name="m_iProgramKey"></param>
        /// <returns></returns>

        public static bool CheckStudentWaitProfile(this Table<Log_RemoveProfile> nLog_RemoveProfile, string m_strStudentKey, int m_iProgramKey)
        {
            var values = from t in nLog_RemoveProfile
                         where t.Training_StudentKey.ToString() == m_strStudentKey &&
                         t.Training_TrainingProgramKey == m_iProgramKey
                         select t;
            if (values.Count() > 0)
                return true;
            else
                return false;
        }
    }
}
